#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

vector<char*> courses[2501];
bool msort(const char* a, const char* b){
    if(a[0]==b[0]){
        if(a[1]==b[1]){
            if(a[2]==b[2]){
                return a[3]<b[3];
            }
            return a[2]<b[2];
        }
        return a[1]<b[1];
    }
    return a[0]<b[0];
}
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    while(n-->0){
        char* name = new char[5];
        int c;
        scanf("%s %d",name,&c);
        while(c-->0){
            int id;
            scanf("%d",&id);
            courses[id].push_back(name);
        }
    }
    for(int i=1;i<=k;i++){
        printf("%d %d\n",i,courses[i].size());
        sort(courses[i].begin(),courses[i].end(),msort);
        for(int j=0;j<courses[i].size();j++){
            printf("%s\n",courses[i][j]);
        }
    }
    return 0;
}
